package com.hxkj.config;

import com.platform.common.domain.result.ResultMessageStruct;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

/**
 * shiro异常处理
 * <p>
 * Create by chenwei on 2018/5/28 19:34
 */
@ControllerAdvice
@ResponseBody
@Slf4j
public class ShiroExceptionHander {


    @ExceptionHandler(UnauthorizedException.class)
    public ResultMessageStruct globalExceptionHandler(HttpServletResponse response, Exception ex) throws Exception {
        ResultMessageStruct result = new ResultMessageStruct();
        response.setStatus(408);
        result.setCode(0);
        result.setMessage("没有权限");
        return result;
    }
}
